#!/bin/sh
yes_no () {
    local default=$2
    while true; do
        echo "$1[y/n](default $default) \c"
        read yes_no 
        if test "$yes_no" = "y" || test "$yes_no" = "";then
            return 0
        elif test "$yes_no" = "n";then
            return 1
        fi
    done
}
userhome=~
echo "Existing Profiles:"
echo "* (Default)"
for f in `ls "$userhome/Library/Application Support/Google/"`
do
    if test "`echo $f|grep Chrome_`" != "";then
        echo '* '$f|sed -e 's/Chrome_//g' -e 's/Chrome//g'
    fi
done
while true;do
    echo "Profile(empty=Default): \c"
    read profile_name
    if test "$profile_name" = "";then
        profile_path="$userhome/Library/Application Support/Google/Chrome"
    else
        profile_path="$userhome/Library/Application Support/Google/Chrome_$profile_name"
    fi
        
    if test ! -d "$profile_path";then
        if yes_no "No this profile, create it?";then
            break
        fi
    else
        break
    fi
done

parameters=""
if ! yes_no "Enable Proxy" y
then
    parameters="$parameters --no-proxy-server"
fi

if ! yes_no "Enable Referrers" n
then
    parameters="$parameters --no-referrers"
fi
echo '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' --user-data-dir="$profile_path" $parameters
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' --user-data-dir="$profile_path" $parameters &
